//Review_JavaScript
/*$(".fakeloader").fakeLoader({
    timeToHide: 1200, //加载效果的持续时间
    zIndex: "999",//
    spinner: "spinner1",//可选值 'spinner1', 'spinner2', 'spinner3', 'spinner4', 'spinner5', 'spinner6', 'spinner7' 对应有7种效果
    bgColor: "#2ecc71", //加载时的背景颜色
});*/
$(function () {

    //Select
    var projectSelect = $("#projectSelect");

    projectSelect.change(function () {

        //SelectValue
        var dataValue = $(this).val();
        var dataArray = dataValue.split(",");

        //AjaxControllerGetData
        $.ajax({
            url: '/Portal/Review/getNumberAction',
            type: 'GET',
            dataType: 'JSON',
            data: {
                instanceId: dataArray[0],
                projectNumber: dataArray[1]
            },
            success: function (data) {
                console.log(data);
                //SetProjectProgressBar
                if (data.tempProjectSpeeds.length != 0) {
                    $("#projectProgress").text(data.tempProjectSpeeds[data.tempProjectSpeeds.length - 1].nowProgreProjectName);
                    $("#projectProgress").css("width", (data.tempProjectSpeeds.length * 10 * 2) + "%");
                } else {
                    $("#projectProgress").css("width", "0%");
                }

                //EachProjectProgressData
                var pillsTab = $("#pills-tab").find("li");
                for (var i = 0; i < pillsTab.length; i++) {
                    if (i != 0) {
                        pillsTab[i].remove();
                    }
                }

                var pillsTabContent = $("#pills-tabContent").find("div[role='tabpanel']");
                ;
                for (var i = 0; i < pillsTabContent.length; i++) {
                    if (i != 0) {
                        pillsTabContent[i].remove();
                    }
                }

                for (var i = 0; i < data.tempProjectSpeeds.length; i++) {
                    var nowtempProjectSpeeds = data.tempProjectSpeeds[i];
                    var tableId = "pills-" + data.tempProjectSpeeds[i].nowProgreProjectName + "-tab";
                    var hrefTabId = "pills-" + data.tempProjectSpeeds[i].nowProgreProjectName;

                    var tabHrefStr = "";
                    tabHrefStr += "<li class='nav-item'>";
                    tabHrefStr += "	<a class='nav-link small' id='" + tableId + "' data-toggle='pill' href='#" + hrefTabId + "'";
                    tabHrefStr += "	role='tab' aria-controls='" + hrefTabId + "' aria-selected='false'>";
                    tabHrefStr += data.tempProjectSpeeds[i].nowProgreProjectName;
                    tabHrefStr += "	</a>";
                    tabHrefStr += "</li>";

                    $("#pills-tab").append(tabHrefStr);

                    var hrefTabStr = '<div class="tab-pane fade" id="' + hrefTabId + '" role="tabpanel" aria-labelledby="' + tableId + '"></div>';

                    $("#pills-tabContent").append(hrefTabStr);

                }

                //SetValue
                $("#createBy").text(data.tempProject[0].createdBy)

                //TimeFormat
                var projectDate = new Date(data.tempProject[0].createdTime);
                $("#projectCreateDate").text(projectDate.getFullYear() + "-" + (projectDate.getMonth() + 1) + "-" + projectDate.getDate() + "  "
                    + projectDate.getHours() + ":" + projectDate.getMinutes() + ":" + projectDate.getSeconds())

                $("#projectNumber").text(data.tempProject[0].projectNumber)
                $("#projectName").text(data.tempProject[0].projectName)
                $("#projectType").text(data.tempProject[0].projectType)
                $("#projectinBudget").text(data.tempProject[0].inBudget)

                //项目组长
                $("#projectLeader").empty();
                if (data.tempProject[0].projectLeader != null) {
                    var leaderArray = data.tempProject[0].projectLeader.split(",");
                    var htmlStr = "";
                    for (var i = 0; i < leaderArray.length - 1; i++) {
                        htmlStr += "<a href='#' class='badge badge-danger ml-1'>" + leaderArray[i] + "</a>";
                    }
                    $("#projectLeader").append(htmlStr);
                } else {
                    $("#projectLeader").append("<a href='#' class='badge badge-danger ml-1'>无参与者</a>");
                }

                //技术评审负责人
                $("#technologyLeader").empty();
                if (data.tempProject[0].technologyLeader != null) {
                    var leaderArray = data.tempProject[0].technologyLeader.split(",");
                    var htmlStr = "";
                    for (var i = 0; i < leaderArray.length - 1; i++) {
                        htmlStr += "<a href='#' class='badge badge-danger ml-1'>" + leaderArray[i] + "</a>";
                    }
                    $("#technologyLeader").append(htmlStr);
                } else {
                    $("#technologyLeader").append("<a href='#' class='badge badge-danger ml-1'>无参与者</a>");
                }

                //技术评审组员
                $("#technologyLeaderUser").empty();
                if (data.tempProject[0].technologyMember != null) {
                    var leaderArray = data.tempProject[0].technologyMember.split(",");
                    var htmlStr = "";
                    for (var i = 0; i < leaderArray.length - 1; i++) {
                        htmlStr += "<a href='#' class='badge badge-danger ml-1'>" + leaderArray[i] + "</a>";
                    }
                    $("#technologyLeaderUser").append(htmlStr);
                } else {
                    $("#technologyLeaderUser").append("<a href='#' class='badge badge-danger ml-1'>无参与者</a>");
                }

                //商务评审负责人
                $("#businessLeader").empty();
                if (data.tempProject[0].businessLeader != null) {
                    var leaderArray = data.tempProject[0].businessLeader.split(",");
                    var htmlStr = "";
                    for (var i = 0; i < leaderArray.length - 1; i++) {
                        htmlStr += "<a href='#' class='badge badge-danger ml-1'>" + leaderArray[i] + "</a>";
                    }
                    $("#businessLeader").append(htmlStr);
                } else {
                    $("#businessLeader").append("<a href='#' class='badge badge-danger ml-1'>无参与者</a>");
                }

                //商务评审组员
                $("#businessLeaderUser").empty();
                if (data.tempProject[0].businessMember != null) {
                    var leaderArray = data.tempProject[0].businessMember.split(",");
                    var htmlStr = "";
                    for (var i = 0; i < leaderArray.length - 1; i++) {
                        htmlStr += "<a href='#' class='badge badge-danger ml-1'>" + leaderArray[i] + "</a>";
                    }
                    $("#businessLeaderUser").append(htmlStr);
                } else {
                    $("#businessLeaderUser").append("<a href='#' class='badge badge-danger ml-1'>无参与者</a>");
                }

                //运管委委员
                $("#operationManager").empty();
                if (data.tempProject[0].operationManager != null) {
                    var leaderArray = data.tempProject[0].operationManager.split(",");
                    var htmlStr = "";
                    for (var i = 0; i < leaderArray.length - 1; i++) {
                        htmlStr += "<a href='#' class='badge badge-danger ml-1'>" + leaderArray[i] + "</a>";
                    }
                    $("#operationManager").append(htmlStr);
                } else {
                    $("#operationManager").append("<a href='#' class='badge badge-danger ml-1'>无参与者</a>");
                }
            }
        })
    })


})


function getRelatedPerson(objectId) {
    $.ajax({
        url: '/Portal/Review/findRelatedPerson',
        type: 'GET',
        dataType: 'JSON',
        data: {
            objectid: objectId
        },
        success: function (data) {
            console.log(data)
            //项目组长
            $("#projectLeader").empty();
            if (data.projectLeader != null) {
                var leaderArray = data.projectLeader.split(",");
                var htmlStr = "";
                for (var i = 0; i < leaderArray.length - 1; i++) {
                    htmlStr += "<a href='#' class='badge badge-danger ml-1'>" + leaderArray[i] + "</a>";
                }
                $("#projectLeader").append(htmlStr);
            } else {
                $("#projectLeader").append("<a href='#' class='badge badge-danger ml-1'>无参与者</a>");
            }

            //技术评审负责人
            $("#technologyLeader").empty();
            if (data.technologyLeader != null) {
                var leaderArray = data.technologyLeader.split(",");
                var htmlStr = "";
                for (var i = 0; i < leaderArray.length - 1; i++) {
                    htmlStr += "<a href='#' class='badge badge-danger ml-1'>" + leaderArray[i] + "</a>";
                }
                $("#technologyLeader").append(htmlStr);
            } else {
                $("#technologyLeader").append("<a href='#' class='badge badge-danger ml-1'>无参与者</a>");
            }

            //技术评审组员
            $("#technologyLeaderUser").empty();
            if (data.technologyMember != null) {
                var leaderArray = data.technologyMember.split(",");
                var htmlStr = "";
                for (var i = 0; i < leaderArray.length - 1; i++) {
                    htmlStr += "<a href='#' class='badge badge-danger ml-1'>" + leaderArray[i] + "</a>";
                }
                $("#technologyLeaderUser").append(htmlStr);
            } else {
                $("#technologyLeaderUser").append("<a href='#' class='badge badge-danger ml-1'>无参与者</a>");
            }

            //商务评审负责人
            $("#businessLeader").empty();
            if (data.businessLeader != null) {
                var leaderArray = data.businessLeader.split(",");
                var htmlStr = "";
                for (var i = 0; i < leaderArray.length - 1; i++) {
                    htmlStr += "<a href='#' class='badge badge-danger ml-1'>" + leaderArray[i] + "</a>";
                }
                $("#businessLeader").append(htmlStr);
            } else {
                $("#businessLeader").append("<a href='#' class='badge badge-danger ml-1'>无参与者</a>");
            }

            //商务评审组员
            $("#businessLeaderUser").empty();
            if (data.businessMember != null) {
                var leaderArray = data.businessMember.split(",");
                var htmlStr = "";
                for (var i = 0; i < leaderArray.length - 1; i++) {
                    htmlStr += "<a href='#' class='badge badge-danger ml-1'>" + leaderArray[i] + "</a>";
                }
                $("#businessLeaderUser").append(htmlStr);
            } else {
                $("#businessLeaderUser").append("<a href='#' class='badge badge-danger ml-1'>无参与者</a>");
            }

            //运管委委员
            $("#operationManager").empty();
            if (data.operationManager != null) {
                var leaderArray = data.operationManager.split(",");
                var htmlStr = "";
                for (var i = 0; i < leaderArray.length - 1; i++) {
                    htmlStr += "<a href='#' class='badge badge-danger ml-1'>" + leaderArray[i] + "</a>";
                }
                $("#operationManager").append(htmlStr);
            } else {
                $("#operationManager").append("<a href='#' class='badge badge-danger ml-1'>无参与者</a>");
            }

            //打开模态框
            $("#PersonModal").modal(true);

        }
    })

}

function getProjectStage(projectNumber) {

    $.ajax({
        url: '/Portal/Review/findRunningData',
        type: 'GET',
        dataType: 'JSON',
        data: {
            projectNumber: projectNumber
        },
        success: function (data) {
            console.log(data);
            //EachProjectProgressData
            var pillsTab = $("#pills-tab").find("li");
            for (var i = 0; i < pillsTab.length; i++) {
                pillsTab[i].remove();
            }

            var pillsTabContent = $("#pills-tabContent").find("div[role='tabpanel']");
            for (var i = 0; i < pillsTabContent.length; i++) {
                pillsTabContent[i].remove();
            }

            for (var i = 0; i < data.length; i++) {
                var nowtempProjectSpeeds = data[i];
                var tableId = "pills-" + data[i].nowProgreProjectName + "-tab";
                var hrefTabId = "pills-" + data[i].nowProgreProjectName;

                var tabHrefStr = "";
                tabHrefStr += "<li class='nav-item'>";

                if (i == 0) {
                    tabHrefStr += "	<a class='nav-link small active' id='" + tableId + "' data-toggle='pill' href='#" + hrefTabId + "'";
                    tabHrefStr += "	role='tab' aria-controls='" + hrefTabId + "' aria-selected='true'>";
                } else {
                    tabHrefStr += "	<a class='nav-link small' id='" + tableId + "' data-toggle='pill' href='#" + hrefTabId + "'";
                    tabHrefStr += "	role='tab' aria-controls='" + hrefTabId + "' aria-selected='false'>";
                }

                tabHrefStr += data[i].nowProgreProjectName;
                tabHrefStr += "	</a>";
                tabHrefStr += "</li>";

                $("#pills-tab").append(tabHrefStr);

                if (i == 0) {
                    var hrefTabStr = '<div class="tab-pane fade active show" id="' + hrefTabId + '" role="tabpanel" aria-labelledby="' + tableId + '">';
                } else {
                    var hrefTabStr = '<div class="tab-pane fade" id="' + hrefTabId + '" role="tabpanel" aria-labelledby="' + tableId + '">';
                }


                if (data[i].datas.length != 0) {
                    hrefTabStr += "<hr><div class=\"row\">";
                    hrefTabStr += "	<div class=\"col small\">";
                    hrefTabStr += "	发起时间:";
                    hrefTabStr += "		<span class=\"pl-2\">";
                    hrefTabStr += data[i].datas.createTime;
                    hrefTabStr += "		</span>";
                    hrefTabStr += "	</div>";
                    hrefTabStr += "</div>";
                    hrefTabStr += "<hr>";
                }

                //验收方案定制
                if (data[i].nowProgreProjectName == "验收方案定制") {

                    if (null != data[i].datas.endTime) {
                        hrefTabStr += "<hr><div class=\"row\">";
                        hrefTabStr += "	<div class=\"col small\">";
                        hrefTabStr += "	结束时间:";
                        hrefTabStr += "		<span class=\"pl-2\">";
                        hrefTabStr += data[i].datas.endTime;
                        hrefTabStr += "		</span>";
                        hrefTabStr += "	</div>";
                        hrefTabStr += "</div>";
                        hrefTabStr += "<hr>";
                    }

                    if (null != data[i].datas.createUser) {
                        hrefTabStr += "<hr><div class=\"row\">";
                        hrefTabStr += "	<div class=\"col small\">";
                        hrefTabStr += "发起人:";
                        hrefTabStr += "		<span class=\"pl-2\">";
                        hrefTabStr += data[i].datas.createUser;
                        hrefTabStr += "		</span>";
                        hrefTabStr += "	</div>";
                        hrefTabStr += "</div>";
                        hrefTabStr += "<hr>";
                    }

                    if (null != data[i].datas.checkDreftPerson) {
                        hrefTabStr += "<hr><div class=\"row\">";
                        hrefTabStr += "	<div class=\"col small\">";
                        hrefTabStr += "[到货验收]&nbsp;验收制定人:";
                        hrefTabStr += "		<span class=\"pl-2\">";
                        hrefTabStr += data[i].datas.checkDreftPerson;
                        hrefTabStr += "		</span>";
                        hrefTabStr += "	</div>";
                        hrefTabStr += "</div>";
                        hrefTabStr += "<hr>";
                    }

                    if (null != data[i].datas.checkPerson) {
                        hrefTabStr += "<hr><div class=\"row\">";
                        hrefTabStr += "	<div class=\"col small\">";
                        hrefTabStr += "[到货验收]&nbsp;验收负责人:";
                        hrefTabStr += "		<span class=\"pl-2\">";
                        hrefTabStr += data[i].datas.checkPerson;
                        hrefTabStr += "		</span>";
                        hrefTabStr += "	</div>";
                        hrefTabStr += "</div>";
                        hrefTabStr += "<hr>";
                    }

                    if (null != data[i].datas.usingDreftPerson) {
                        hrefTabStr += "<hr><div class=\"row\">";
                        hrefTabStr += "	<div class=\"col small\">";
                        hrefTabStr += "[使用验收]&nbsp;验收制定人:";
                        hrefTabStr += "		<span class=\"pl-2\">";
                        hrefTabStr += data[i].datas.usingDreftPerson;
                        hrefTabStr += "		</span>";
                        hrefTabStr += "	</div>";
                        hrefTabStr += "</div>";
                        hrefTabStr += "<hr>";
                    }

                    if (null != data[i].datas.usingPerson) {
                        hrefTabStr += "<hr><div class=\"row\">";
                        hrefTabStr += "	<div class=\"col small\">";
                        hrefTabStr += "[使用验收]&nbsp;验收负责人:";
                        hrefTabStr += "		<span class=\"pl-2\">";
                        hrefTabStr += data[i].datas.usingPerson;
                        hrefTabStr += "		</span>";
                        hrefTabStr += "	</div>";
                        hrefTabStr += "</div>";
                        hrefTabStr += "<hr>";
                    }


                }


                //项目总结
                if (data[i].nowProgreProjectName == "项目总结") {

                    if (null != data[i].datas.projectUseNeedDate) {
                        hrefTabStr += "<hr><div class=\"row\">";
                        hrefTabStr += "	<div class=\"col small\">";
                        hrefTabStr += "项目立项用时:";
                        hrefTabStr += "		<span class=\"pl-2\">";
                        hrefTabStr += data[i].datas.projectUseNeedDate;
                        hrefTabStr += "		</span>";
                        hrefTabStr += "	</div>";
                        hrefTabStr += "</div>";
                        hrefTabStr += "<hr>";
                    }

                    if (null != data[i].datas.projectUseAssessDate) {
                        hrefTabStr += "<hr><div class=\"row\">";
                        hrefTabStr += "	<div class=\"col small\">";
                        hrefTabStr += "方案评估用时:";
                        hrefTabStr += "		<span class=\"pl-2\">";
                        hrefTabStr += data[i].datas.projectUseAssessDate;
                        hrefTabStr += "		</span>";
                        hrefTabStr += "	</div>";
                        hrefTabStr += "</div>";
                        hrefTabStr += "<hr>";
                    }

                    if (null != data[i].datas.projectUseCheckDate) {
                        hrefTabStr += "<hr><div class=\"row\">";
                        hrefTabStr += "	<div class=\"col small\">";
                        hrefTabStr += "合同评审用时:";
                        hrefTabStr += "		<span class=\"pl-2\">";
                        hrefTabStr += data[i].datas.projectUseCheckDate;
                        hrefTabStr += "		</span>";
                        hrefTabStr += "	</div>";
                        hrefTabStr += "</div>";
                        hrefTabStr += "<hr>";
                    }

                    if (null != data[i].datas.projectUseTotalDate) {
                        hrefTabStr += "<hr><div class=\"row\">";
                        hrefTabStr += "	<div class=\"col small\">";
                        hrefTabStr += "验收实施用时:";
                        hrefTabStr += "		<span class=\"pl-2\">";
                        hrefTabStr += data[i].datas.projectUseTotalDate;
                        hrefTabStr += "		</span>";
                        hrefTabStr += "	</div>";
                        hrefTabStr += "</div>";
                        hrefTabStr += "<hr>";
                    }


                }

                hrefTabStr += "</div>";

                $("#pills-tabContent").append(hrefTabStr);

            }

        }
    })

    $("#ProjectStageDataModal").modal(true);
}
